package com.xtx.air.web.commons;

import java.io.File;
import java.io.IOException;
import java.util.List;

import net.sf.json.JSONArray;

import org.apache.commons.io.FileUtils;

public final class DatasCache {

	public static void main(String[] args) throws Exception {
		FileUtils.writeStringToFile(new File("D:/cities.json"), JSONArray.fromObject(getCities()).toString(), "UTF-8");
	}

	@SuppressWarnings("unchecked")
	public static List<String> getCities() throws IOException {
		return FileUtils.readLines(FileUtils.toFile(getClassLoader().getResource("datas/airport.txt")), "UTF-8");
	}

	private static ClassLoader getClassLoader() {
		ClassLoader classLoader = DatasCache.class.getClassLoader();
		if (classLoader == null) {
			classLoader = Thread.currentThread().getContextClassLoader();
		}
		return classLoader;
	}
}